﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using University.Workshop.Model;


namespace University.Workshop.DataAccess
{
    public static class ClientUpdater
    {
        // Crear un cliente
        public static void UpdateClient(string fullName, string id, string telephone, int ids)
        {
            Client client = new Client { FullName = fullName, ClientId = id, Telephone = telephone };
            UpdateClient(client, ids);
        }

        // Actualizar datos del cliente
        public static void UpdateClient(Client client, int ids)
        {
            if (client == null)
                throw new ArgumentException("Invalid Input Parameters");

            // La cadena de conexión
            const string conecctionString = "Data Source=.\\SQLEXPRESS; Initial Catalog=DataBaseHotel; Integrated Security=True";

            // Conectar y actualizar los datos
            using (SqlConnection conn = new SqlConnection(conecctionString))
            {
                SqlCommand cmdUpdate;

                using (cmdUpdate = new SqlCommand())
                {
                    cmdUpdate.Parameters.Clear();

                    cmdUpdate.CommandText = "UPDATE [Client] SET [FullName] = @FullName, [ClientId] = @ClientId, " +
                    "[Telephone] = @Telephone WHERE [id]=" + ids;

                    cmdUpdate.CommandType = CommandType.Text;
                    cmdUpdate.Connection = conn;

                    cmdUpdate.Parameters.Add(new SqlParameter("@FullName", client.FullName));
                    cmdUpdate.Parameters.Add(new SqlParameter("@ClientId", client.ClientId));
                    cmdUpdate.Parameters.Add(new SqlParameter("@Telephone", client.Telephone));

                    conn.Open();

                    cmdUpdate.ExecuteNonQuery();
                }
            }
        }
    }
}
